USE GESTION2
go
IF OBJECT_ID('dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR
    IF OBJECT_ID('dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR >>>'
END
go
SET ANSI_NULLS ON
go
SET QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE [dbo].[WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR]
AS

BEGIN
select a.ctnro, count(b.z07369ct2) as num_trabajadores into dbo.TotalTabajador 
from 
  fsd008 as a (nolock) Left Join z07369 as b (nolock) ON a.ctnro = b.z07369ct1  
where a.ctccli in(1,2) 
group by a.ctnro

END
go
SET ANSI_NULLS OFF
go
SET QUOTED_IDENTIFIER OFF
go
IF OBJECT_ID('dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.WASP_D0004_CREA_TABLA_TOTAL_TRABAJADOR >>>'
go
